package com.yugao.fintech.draper.admin.handler;

import com.yugao.fintech.draper.admin.service.RouteConfigService;
import com.yugao.fintech.draper.auth.mq.RouteMessage;
import com.yugao.fintech.draper.message.queue.client.RedisMQTemplate;
import com.yugao.fintech.draper.auth.dto.RouteConfVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
@RequiredArgsConstructor
public class DynamicRouteLoadHandler implements SmartInitializingSingleton {

	private final RouteConfigService routeConfigService;

	private final RedisMQTemplate redisMQTemplate;

	/**
	 * 加载路由信息到redis
	 */
	@Override
	public void afterSingletonsInstantiated() {
		List<RouteConfVO> route = routeConfigService.findAll();
		log.debug("加载到路由信息:{}", route);
		redisMQTemplate.send(new RouteMessage(route));
	}
}
